﻿@model pbvs.Models.ViewModels.FormElementViewModel
@{
    Layout = "~/Views/Shared/_ManageLayout.cshtml";
}  
<h2>FormElement</h2>
@Html.Hidden("FormElementModel", Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model)))
@using (Html.BeginForm("FormElement", "Manage", FormMethod.Post))
{
		<div>
			<div class="">
				@Html.LabelFor(m => m.Field)
			</div>
			<div class="">
				@Html.DropDownListFor(m => m.Field, Model.ElementsDropDown)
			</div>
		</div>
		<div>
			<div class="">
				@Html.LabelFor(m => m.HelpText)
			</div>
			<div class="">
				@Html.TextBoxFor(m => m.HelpText, new { @style = "width:500px;" })
			</div>
		</div>
	<button>Save</button>
}
@{Html.Assets().Scripts.Add(@Url.Content("~/Scripts/linq.js"));}
<script type="text/javascript">
    var vm;

    $(function () {
        vm = $.parseJSON($("#FormElementModel").val());
        $("#Field").on("change", function () {
            var elem = Enumerable.From(vm.Elements).Where(function (item) { return item.Field == $("#Field").val(); }).Select(function (item) { return item; }).First();
            $("#HelpText").val(elem.HelpText);
        });
    });
</script>